#include "mytextedit.h"

MyTextEdit::MyTextEdit(QWidget *parent) : QTextEdit(parent)
{

}

void MyTextEdit::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Control) {
        _pressCtrl = true;
    }
    QTextEdit::keyPressEvent(event);
}

void MyTextEdit::keyReleaseEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Control) {
        _pressCtrl = false;
    }
    QTextEdit::keyPressEvent(event);
}

void MyTextEdit::wheelEvent(QWheelEvent *event)
{
    if (_pressCtrl) {
        if (event->angleDelta().y() == 120) {
            zoomIn();
        } else if (event->angleDelta().y() == -120) {
            zoomOut();
        }
    }
    //注意需要让滚轮事件继续向上传递 否则会没有办法往下面滚动
    QTextEdit::wheelEvent(event);
}
